﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>预收款</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/goodsSelecter.js"></script>
<script type="text/javascript" src="../js/vouchersTypeSelecter.js"></script>
<script type="text/javascript" src="../js/couponSelecterNew.js"></script>
<script type="text/javascript" src="../js/scheduleTypeSelecter.js"></script>
<script type="text/javascript" src="../js/lisenseSelecterNew.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<script type="text/javascript" src="../js/manhuaDate.1.0.js"></script> 
<script type="text/javascript">
var _memberIntegral =  null;
var _memberDeposit =  null;
var _memberId =  null;
var IntegralRule = 0;
var integralVote = 0;
$(function(){
	$('#makeDate').val(getToday())
	$(".check_btn").click(function(){
		
		var shopId = getInputValue("shopName");
		var ScheduleTypeId = getInputValue("ScheduleType");
  		if(IsEmpty(shopId)){
  			artError("请先选择店铺")
  			return false;
  		}
  		if(IsEmpty(_memberId)){
  			artError("请先选择会员")
  			return false;
  		}
  		var giveMoney = $("#Amount").val()
  		var depositAmount = $("#depositAmount").val()
  		$("#faceMoney").val(giveMoney)
		$("#posMoney").val(0)
		$("#despoitMoney").val(0)
		$("#integralMoney").val(0)
		$("#ycfk").html("(可用金额："+depositAmount+")")
		$("#djqMoney").val(0)
		$("#fkMoney").val(0)
		$("#coupMoney").val(0)
		if(IntegralRule==0){
			$("#integralMoney").attr("disabled",true);
			$("#jfdx").html("(暂无可用规则)")

		}else{
			
			$("#integralMoney").attr("disabled",false);
			$("#jfdx").html("(可用积分:"+_memberIntegral+",可用抵现金额："+(_memberIntegral/integralVote).toFixed(2)+")")
		}
		addMargin($(".coinHome"))
		$(".coinHome,#yinying1").show();
	})
	
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			$("#research").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});
	
	$(".receivedMoney").change(function(){
		var money = $(this).val()
		money = parseFloat(money);
		if(isNaN(money)){
			money=0;
		}
		if(IsNotEmpty(money)&&money!=0){
			$(this).val(money)
			var coupMoney = parseFloat( getInputValue("coupMoney")).toFixed(2);
			var despoitMoney =parseFloat( getInputValue("despoitMoney")).toFixed(2);
			var integralMoney =parseFloat( getInputValue("integralMoney")).toFixed(2);
			var djqMoney =parseFloat( getInputValue("djqMoney")).toFixed(2);
			var posMoney =parseFloat( getInputValue("posMoney")).toFixed(2);
			
			var all=parseFloat(coupMoney)+parseFloat(integralMoney)+parseFloat(despoitMoney)+parseFloat(djqMoney)+ parseFloat(posMoney)
			 $("#fkMoney").val(all)
		}else{
			$(this).val(0)
			var coupMoney = parseFloat( getInputValue("coupMoney")).toFixed(2);
			var despoitMoney =parseFloat( getInputValue("despoitMoney")).toFixed(2);
			var djqMoney =parseFloat( getInputValue("djqMoney")).toFixed(2);
			var posMoney =parseFloat( getInputValue("posMoney")).toFixed(2);
			var integralMoney =parseFloat( getInputValue("integralMoney")).toFixed(2);
		var all=parseFloat(coupMoney)+parseFloat(integralMoney)+parseFloat(despoitMoney)+parseFloat(djqMoney)+ parseFloat(posMoney)
			 $("#fkMoney").val(all)
		}
	})
	
	$(".raceMoney").change(function(){
		var allMoney =parseFloat( getInputValue("allMoney")).toFixed(2);
		var wipeZeroAmt = getInputValue("wipeZeroAmt");
		var freeAmt = getInputValue("freeAmt");
		var facemoney = parseFloat(allMoney)- parseFloat(wipeZeroAmt)-parseFloat(freeAmt);
		 $("#faceMoney").val(facemoney.toFixed(2))
		 $("#coupMoney").val(facemoney.toFixed(2))
		 $("#fkMoney").val(facemoney.toFixed(2))
	})
	
	
	$("#sk").keypress(function(event){
		if(event.keyCode==13){
		 var sk = 	$(this).val().replace(/\s/gi,'')
		 var cash = getInputValue("coupMoney");
		 
		 $("#zlMoney").val((parseFloat(sk)- parseFloat(cash)).toFixed(2))
		}
	})
	resetMemberInfo();
	resetRoomInfo()
	getIntegralRule();

})
function getIntegralRule(){
	var dt  = _findInfo("../memberIntRule/find/memberIntegralRuleByName", {'name':'积分抵现','status':1})
	if(IsNotEmpty(dt)&&dt.state==0){
		IntegralRule = _getIntOfJson(0, dt, "RuleID")
		integralVote = _getIntOfJson(0, dt, "IntegralRate");
	}
}

function resetMemberInfo(){
	_memberId = null;
	 _Discout = null;
	 _memberDeposit =  null;
	 _memberId =  null;
	 _cashCouponAmount = null;
	$("#cardNo").val("");
	$("#customerName").val("");
	$("#levelName").val("");
	$("#cashCouponAmount").val("");
	$("#depositAmount").val("");
	$("#discount").val("");
}


function searchMember(){
	resetMemberInfo();
}

function searchMember(){
		
			var cardno = $("#memberCardNo").val().replace(/\s/gi,'')
			if(IsNotEmpty(cardno)){
				
				getShopMember();
			}else{
				
				resetMemberInfo();
			}	
}

function getShopMember(){//查询会员信息
	var shopId = getInputValue("shopName");
	if(IsEmpty(shopId)){
		artError("请先选择店铺")
		return false;
	}
	var memberCardNo = getInputValue("memberCardNo")
	if($("#memberSelect").val()==1){
	var param = {'shopId':shopId,'memberCardNo':memberCardNo}
	}else{
		var param = {'shopId':shopId,'name':memberCardNo}
	}
	 memberInfo = _findInfoPost("../shopmember/find/memberDespoist", param)
	if(IsNotEmpty(memberInfo)&&memberInfo.state==0){
		if(memberInfo.result.data.length==0){
			 _Discout = null;
			_cashCouponAmount = null;
			 _memberDeposit =  null;
			resetMemberInfo();
			
			alertErrorMessage("查无此会员")
		}else{
		if(memberInfo.result.data.length==1){
			
		$("#cardNo").val(_getStringOfJson(0, memberInfo, "memberCardNo"));
		$("#levelName").val(_getStringOfJson(0, memberInfo, "levelName"))
		$("#integralAmount").val(_getStringOfJson(0, memberInfo, "integralAmount"))
		$("#customerName").val(_getStringOfJson(0, memberInfo, "customerName"))
		$("#roomNo").val(_getStringOfJson(0, memberInfo, "license"))
		_Discout = _getStringOfJson(0, memberInfo, "discount");
		_memberDeposit = _getStringOfJson(0, memberInfo, "depositAmount")
		_cashCouponAmount = _getStringOfJson(0, memberInfo, "cashCouponAmount")
			_memberIntegral = _getStringOfJson(0, memberInfo, "integralAmount")
		_memberId = _getStringOfJson(0, memberInfo, "id")
		$("#discount").val(_Discout)
		$("#depositAmount").val(_memberDeposit)
		$("#cashCouponAmount").val(_cashCouponAmount)
		restZk()
		}else{
			loadmember(memberInfo)
		}	
		
		}		
	}
	
	$("#memberCardNo").val("");
}

function loadmember(memberInfo){
		$("#memberList").empty()
	for ( var i = 0; i < memberInfo.result.data.length; i++) {
		var htm="<tr>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "memberCardNo")+"</td>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "customerName")+"</td>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "mp")+"</td>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "integralAmount")+"</td>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "depositAmount")+"</td>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "cashCouponAmount")+"</td>"
			htm+="<td>"+_getStringOfJson(i, memberInfo, "License")+"</td>"
			htm+="<td><input type=\"button\"  value=\"选择\" class=\"common_btn\" onclick='chooseMember("+_getStringOfJson(i, memberInfo, "memberId")+")' ></td>"
			htm+="</tr>"
			$("#memberList").append(htm)
	}
	addMargin($("#memberDiv"))
	$("#memberDiv,#yinying1").show();
	
}
function chooseMember(id){
	for ( var i = 0; i < memberInfo.result.data.length; i++) {
		var ids = _getStringOfJson(i, memberInfo, "memberId")
		if(id==ids){
			$("#cardNo").val(_getStringOfJson(i, memberInfo, "memberCardNo"));
			$("#levelName").val(_getStringOfJson(i, memberInfo, "levelName"))
			$("#integralAmount").val(_getStringOfJson(i, memberInfo, "integralAmount"))
			$("#customerName").val(_getStringOfJson(i, memberInfo, "customerName"))
			$("#roomNo").val(_getStringOfJson(i, memberInfo, "license"))
		_Discout = _getStringOfJson(i, memberInfo, "discount");
			_memberDeposit = _getStringOfJson(i, memberInfo, "depositAmount")
			_cashCouponAmount = _getStringOfJson(i, memberInfo, "cashCouponAmount")
		_memberIntegral = _getStringOfJson(0, memberInfo, "integralAmount")
			_memberId = _getStringOfJson(i, memberInfo, "id")
			$("#discount").val(_Discout)
			$("#depositAmount").val(_memberDeposit)
			$("#cashCouponAmount").val(_cashCouponAmount)
		}
	}
	$("#memberDiv,#yinying1").hide();

}

function checkFk(){
	
		var needDes = parseInt( $("#despoitMoney").val());
		var hasDes = parseInt( $("#depositAmount").val())
		if(needDes>hasDes){
			artError("预存不足")
			return false;
		}
	
		var faceMoney = getInputValue("faceMoney");
		var fkMoney = getInputValue("fkMoney");
		if(parseFloat( fkMoney) == parseFloat( faceMoney )){
			art.dialog({fixed:true, lock: true,content:"确认收款完成？",icon:'question',ok: function (){
				saveInfo2()
			},cancel:true});
		}else if(parseFloat( fkMoney) < parseFloat( faceMoney )){
			artError("付款不足")
			return false;
		}else if(parseFloat( fkMoney) > parseFloat( faceMoney )){
			art.dialog({fixed:true, lock: true,content:"付款("+fkMoney+")大于实收("+faceMoney+"),是否确定交易？",icon:'question',ok: function (){
				saveInfo2()
			},cancel:true});
		}
		
	
}


function saveInfo2(){
	var shopId = getInputValue("shopName");
	var roomNo = getInputValue("roomNo");
	var giveMoney = getHtmlValue("giveMoney");
	var faceMoney = getInputValue("faceMoney");
	var coupMoney = getInputValue("coupMoney");
	var despoitMoney = getInputValue("despoitMoney");
	var integralMoney = getInputValue("integralMoney");
	var djqMoney = getInputValue("djqMoney");
	var posMoney = getInputValue("posMoney");
	var memo = getInputValue("Memo");
	
	var fkMoney = getInputValue("fkMoney");

	var heads = new Array("ShopID","MemberID","FaceValue","Memo","CashAmt","DepositAmt","BankAmt","OtherAmt","License","intergalAmt")
	var datas = new Array(shopId,_memberId,faceMoney,memo,coupMoney,despoitMoney,posMoney, djqMoney,roomNo,integralMoney)
	var jsonDate= _getJsonParseInsertStr(heads, datas);
	if(IsNotEmpty(_memberId)){
			 m = _insertInfoNoSucceedMessage("../memberCashCoupBill/insert/insertMember", {"data":jsonDate})
		 if(IsNotEmpty(m)){
			 var id= getHeadIndexValue(0, m, "id");
				var billNO = getHtmlString(getHeadIndexValue(0,m, "billNo"));

			 if(m.state==0){
				 art.dialog({fixed:true, lock: true,content:"交易完成,是否打印销售单？",icon:'question',ok:function(){
					 toPrintSaleBill(billNO,shopId)
				 },cancel:true});	
				 resetMemberInfo();
				 resetRoomInfo();
					$(".coinHome,#yinying1").hide();
					$("#toPassword,#yinying2").hide();
			 }
		}
	}
	
}



function toPrintSaleBill(billNo,shopId){
	window.open('printCashCoupBill.html?billNo='+billNo+'&shopId='+shopId+"&flag=2")

}



function resetRoomInfo(){
	$("#Amount").val("")
	$("#Memo").val("")
	$("#roomNo").val("")

}

function  __lisenseSelected(lisenseId, lisenseName,mp) {
	$("#roomNo").val(mp)
	closeLisenseListPanel()
}
</script>
<div id="memberDiv" class="hideDiv" style="display:none;">
  <div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
  <table width="100%" border="0" cellspacing="1" cellpadding="0" class="member_list">
    <caption>
    <strong>会员列表 <span id="sup">共 575 条</span></strong>
    </caption>
    <thead>
      <tr>
        <th>卡号</th>
        <th>姓名</th>
        <th>手机</th>
        <th>积分</th>
        <th>现金账户</th>
        <th>点金券</th>
        <th>车牌号</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody id="memberList">
    	
    </tbody>
  </table>
</div>
<div id="yinying1" style="display:none;"></div>
<div id="yinying2" style="z-index: 599"></div>

<div class="hideDiv coinHome member_search">
  <div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
  <p>
    <label><span>实收：</span>
      <input type="text" id="faceMoney" value="0"  readonly="readonly">
    </label>
  </p>
  <p style="padding-top: 10px; border-top: 2px solid rgb(220, 220, 220);">
    <label><span>现金付款：</span>
      <input type="text" id="coupMoney" value="0" class="receivedMoney">
    </label>
    </p><p>
    <label><span>POS付款：</span>
      <input type="text" id="posMoney" value="0"  class="receivedMoney">
    </label>
  </p>
  <p>
    <label><span>预存付款：</span>
      <input type="text" id="despoitMoney" value="0"  class="receivedMoney">
    </label>
    <label><span id="ycfk">(可用金额：)</span> </label>
  </p>
   <p>
    <label><span>积分抵现：</span>
      <input type="text" id="integralMoney" value="0"  class="receivedMoney">
    </label>
    <label><span id="jfdx"> (可用积分：)</span> </label>
  </p>
  <p>
    <label><span>其它：</span>
      <input type="text" id="djqMoney" value="0"  class="receivedMoney">
    </label>
  </p>
   <p  style="padding-top: 10px; border-top: 2px solid rgb(220, 220, 220);"><!-- style="display: none;" --> 
    <label ><span>总付款：</span>
      <input type="text" id="fkMoney" value="0" readonly class="receivedMoney">
    </label>
  </p>
  <div class="BottomBtn">
    <input type="button" value="确认付款" onclick="checkFk()">
  </div>
</div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">店面收银</div> 
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
        <select id="shopName" onclick="openShopListPanel(this)" style=";height:20px;" disabled="disabled">
        </select>
  
        
      </p>
      </br>
      <div class="knowPerson">
        <p class="knowAll">
          <span><select id="memberSelect" style="width: 80px;" >
          	<option value="1">会员卡号</option>
          	<option value="2">会员姓名</option>
          </select>：</span><label> 
            <input type="text" id="memberCardNo" class="absoluteTxt"  onkeypress="if(event.keyCode==13){searchMember()}" >
          </label>
          <input class="btn common_btn" name="查询" type="button" value="清除会员信息" onclick="resetMemberInfo()" >
        </p>
        <p class="knowAll">
          <label> <span>会员卡号：</span>
            <input type="text" readonly id="cardNo" class="memberInfo">
          </label>
          <label> <span>会员姓名：</span>
            <input type="text" readonly id="customerName" class="memberInfo">
          </label>
          <label> <span>会员级别：</span>
            <input type="text" id="levelName" readonly class="memberInfo">
          </label>
        </p>
        <p class="knowAll">
          <label> <span>预存金额：</span>
            <input type="text" readonly id="depositAmount" class="memberInfo">
          </label>
          <label> <span>代金券（预收款）：</span>
            <input type="text" readonly id="cashCouponAmount" class="memberInfo">
          </label>
          <label> <span>会员折扣：</span>
            <input type="text" readonly id="discount" class="memberInfo">
          </label>
        </p>
      </div>
      <br>
      <p>
        <span>车牌号：</span>
        <input type="text" value="" id="roomNo" class="absoluteTxt">
        <input class="btn common_btn" type="button" onclick="openLisenseListPanel(this)" value="选择" >
      </p>
      
       <br>
			  		 <p style="padding-top: 10px; border-top: 2px solid rgb(220, 220, 220);"></p>
			  		<br>
				  	<p><label><span>代金券/预收款：</span><input type="text" id="Amount" class="clearValue" ></label><em id="ts" style="color: red;"></em></p>
				  	<p><label><span>备注：</span><textarea id="Memo" class="clearValue" style="width: 500px;"></textarea></label></p>
				</form>
				<div class="BottomBtn" >
					<input id="paid_btn" class="check_btn common_btn" value="付款" type="button" >
				</div>
    </div>
    
  </div>
  <div class="fc"></div>
</div>

<!-- InstanceEndEditable --> 
<
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
addMargin($(".hideDiv"))
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
